package com.cskaoyan.utils;

import com.mysql.jdbc.Driver;
import com.sun.corba.se.pept.transport.ConnectionCache;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.concurrent.Callable;

/**
 * 创建日期: 2022/07/25 17:49
 *
 * @author ciggar
 */
public class JDBCUtils {

    /** 1. 注册驱动
     *
     *  2. 可配置化
     *
     *  3. 关闭ResultSet
     *
     */


    static Connection connection;


    static {
        try {

            // 注册驱动
            DriverManager.registerDriver(new Driver());

            // 建立连接
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/43th?useSSL=false&characterEncoding=utf8",
                    "root",
                    "123456"
            );
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }


    // 获取连接
    public static Connection getConnection(){

        return connection;

    }

    // 关闭资源
    public static void closeResource(Statement statement,Connection connection){
        try {
            statement.close();
            connection.close();
        }catch (Exception ex) {
            ex.printStackTrace();
        }
    }


}
